package com.atguigu.gmall.realtime.app.fun;

import com.atguigu.gmall.realtime.utils.KeyWordUtil;
import org.apache.flink.table.annotation.DataTypeHint;
import org.apache.flink.table.annotation.FunctionHint;
import org.apache.flink.table.functions.TableFunction;
import org.apache.flink.types.Row;

import java.io.IOException;
import java.util.List;

/**
 * ClassName: SplitFunction
 * Package: com.atguigu.gmall.realtime.app.fun
 * Description:
 *
 * @Author ChenJun(有志男青年)
 * @Create 2023/5/5 15:58
 * @Version 1.0
 */
@FunctionHint(output = @DataTypeHint("ROW<word STRING>"))
public class SplitFunction extends TableFunction<Row> {


    public void eval(String keyword) {

        try {
            List<String> list = KeyWordUtil.splitKeyWord(keyword);
            for (String word : list) {
                collect(Row.of(word));
            }
        } catch (IOException e) {
            collect(Row.of(keyword));
        }
    }

}
